/*
	Drone Routines - Supporting Combat/Mining Drone Types (others can be added if anyone needs them)
															- Hessinger
		
	Developer Notes
														
	Notes From Hessinger:
	 - Currently will only support one type of drone at a time
	 
*/

objectdef obj_Drone
{
	variable string CurrentState
	variable int Pulse
	variable index:int ActiveDroneIDList
	variable int AsteroidCategoryID = 25
	variable index:item DronesInBay
	
	method Initialize()
	{
		echo "obj_Drones: Check Sum Complete"
	}
	
	method Shutdown()
	{
		echo "obj_Drones: Shutting Down"
		Event[OnFrame]:DetachAtom[This:Pulse]
	}
	
	method StatePulse()
	{
		Pulse:Inc
		variable int IntervalInSeconds = 6
		
		if ${Pulse} >= ${Math.Calc[${Display.FPS} * ${IntervalInSeconds}]}
		{
			echo "Debug: Current State: ${This.CurrentState}"
			echo "Debug: Current Drone State: ${This.DroneState}"
			echo "Debug: Current Drone Type: ${This.DroneType}"
			
			; Hess's Cheat Sheet
			;
			; Mining Drone States
			; -2 No Active Drones
			; -1 ERROR
			; 0 Idle
			; 2 Mining
			; 4 Returning to Drone Bay
			
			
			; HERES HOW THIS WORKS, FIRST YOU HAVE GENERIC STATES FOR ALL DRONE TYPES.
			; THEN WE BREAK IT DOWN INTO TYPES
			
			if ${Me.ToEntity.Mode} == 3 || ${Me.InStation}
			{				
					This.CurrentState:Set["WAITING"]
					Pulse:Set[0]
					return	
			}
			
			;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
			; NEED TO ADD SOME FLAGS IN OUR SCRIPTS, something like IsAboutToWarp. ;
			; 	also possibly need to get cargo checks and other crap in here 		 ;
			;                                                    - Hess						 ;
			;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
			
			;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
			;							Also need arguements to return the drones								 ;
			;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
			
			if ${Me.Ship.GetDrones} > 0 && ${This.DronesInSpace} == 0
			{
					This.CurrentState:Set["DEPLOY"]
					This:DeployDrones
					Pulse:Set[0]
					return
			}
			
			if ${This.DroneType.Equal["Mining"]}
			{
				if ${This.DroneState} == 2
				{
					This.CurrentState:Set["MINING"]
					Pulse:Set[0]
					return
				}
				
				if (${Me.ActiveTarget.CategoryID} == ${This.AsteroidCategoryID}) && (${This.DroneState} != 2)
				{
					This.CurrentState:Set["MINE"]
					This:Mine
					Pulse:Set[0]
					return
				}
			}
			
			;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
			;													Need Targeting Methods												;
			;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
			
			if ${This.DroneType.Equal["Combat"]}
			{
				
			}
			
			This.CurrentState:Set["NONE"]
			Pulse:Set[0]
			
		}
	}
	
	; Will only support 1 type of drone currently
	member:string DroneType()
	{
		
		if ${This.DronesInSpace} == 0
		{
			return "NONE IN SPACE"
		}
		
		variable iterator OurDrones
		This.ActiveDroneIDList:GetIterator[OurDrones]

			if ${Entity[${OurDrones.Value}].GroupID} == 101
			{
				return "Mining"
			}
					
			if ${Entity[${OurDrones.Value}].GroupID} == 100
			{
				return "Combat"
			}
		return "Unknown"
		
	}
	
	
	;This will only return the state of the first drone, typically if one drone is doing something the others will be too.
	member:int DroneState()
	{
		if ${This.DronesInSpace} == 0
		{
			return -2
		}
		
		variable iterator OurDrone
		This.ActiveDroneIDList:GetIterator[OurDrone]
		
		if ${OurDrone:First(exists)}
		{
			;echo ${OurDrone.Value}
			;echo ${Entity[${OurDrone.Value}].ToActiveDrone.State}
			return ${Entity[${OurDrone.Value}].ToActiveDrone.State}
		}

		return -1
	}
	
	member:int DronesInSpace()
	{
		return ${Me.GetActiveDroneIDs[This.ActiveDroneIDList]}
	}
	
	method DeployDrones()
	{
		Me.Ship:LaunchAllDrones
	}
	
	method Mine()
	{
		EVE:DronesMineRepeatedly[This.ActiveDroneIDList]
	}
	
}